<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/css/bootstrap.css">
<link href="${ctx }/js/plugs/font-awesome-4.2.0/css/font-awesome.css" rel="stylesheet">
<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx }/js/plugs/jquery-ui-1.10.3.custom/js/jquery-1.10.1.js"></script>
<script type="text/javascript" src="${ctx }/js/plugs/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.js"></script>
<script type="text/javascript" src="${ctx }/js/dw/responsive-width.js"></script>
<script language="javascript" type="text/javascript" src="${ctx }/js/plugs/My97DatePickerBeta/My97DatePicker/WdatePicker.js"></script>
<link href="${ctx }/css/dw-user.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/js/plugs/font-awesome-4.2.0/css/font-awesome.css" rel="stylesheet">

<title>分组发布</title>
<script type="text/javascript">
	
$(document).ready(function(){
	currentMenu("groupmanager");
	$(".checkboxAll").unbind();
	$(".checkboxAll").change(function(){
		if($(this).prop("checked")){
			$(".quItemCheckbox").prop("checked",true);
		}else{
			$(".quItemCheckbox").prop("checked",false);
		}
	});
	
	$(".quItemCheckbox").change(function(){
		var noCheckeds=$(".quItemCheckbox").not(":checked");
		if(noCheckeds[0]){
			$(".checkboxAll").prop("checked",false);
		}else{
			$(".checkboxAll").prop("checked",true);
		}
	});
	
	
	//控制回显
	objcked = document.getElementsByName("groupIdChecked");
	objList = document.getElementsByName("groupId");
    for(k in objcked){
		for(j in objList) {
			if(objList[j].value == objcked[k].value) {
				objList[j].checked=true;
				
			}
		}
    }

	$('#saveBtn').bind("click",function() {
	    obj = document.getElementsByName("groupId");
	    check_val = [];
	    for(k in obj){
	        if(obj[k].checked)
	            check_val.push(obj[k].value);
	    }
	    
	    var groupId = check_val.join('#');
	    var ctx= $("#ctx").val();
	    //如果发布在ROOT下会出现异常，可能是由于弹出窗口导致的，强行补丁
	    if (ctx == null) {
	    	ctx = "";
	    }
	    //先check一下按学号发布是否勾选
	    var surveyId = $('#surveyId').val();
		var url=ctx+"/design/my-survey-design-group/ajaxCheck.do";
		var data="surveyId="+surveyId + "&groupId=" + groupId;
		$.ajax({
			url:url,
			data:data,
			type:"post",
			success:function(msg){
				if (msg == "false") {
					alert("未设置学号检验属性,无法保存");
				} else {
					url=ctx+"/design/my-survey-design-group/ajaxSave.do";
					data="surveyId="+surveyId + "&groupId=" + groupId;
					$.ajax({
						url:url,
						data:data,
						type:"post",
						success:function(msg){
							alert("保存成功");
							window.close();
						}
					});
				}
			}
		});
});
});
</script>
<style type="text/css">
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default{
	background: #EFEFEF;
}
.usGroupUl{
	list-style: none;
	padding: 5px;
}
.usGroupUl li{
	list-style: none;
	font-size: 14px;
}
.usGroupUl li a{
	color: #333;
}
.new-dialog .ui-dialog-buttonset button{
	padding: 5px 10px;
}
</style>
</head>
<body>
	<div style="clear: both;"></div>
	<div id="dwBody" style="margin-top: 15px;" >
		<div id="dwBodyContent" class="bodyCenter" style="">
		<div id="dwBodyUser">
			<div class="surveyCollectMiddle">
				
				<div class="surveyCollectMiddleContent">
					<div style="padding: 25px 45px;overflow: auto;padding-top: 12px;">
							<div style="padding: 5px;color: #666565;letter-spacing: 2px;font-size: 18px;">选择小组</div>
							
							<div class="contacts_search" style="padding: 5px;color:#666565;margin-top: 15px;" >
								<form id="formSearch" action="${ctx }/design/my-survey-design-group/list.do?surveyId=${surveyId }" method="post">
								<div style="padding-left: 30px;padding-top: 8px;padding-bottom: 8px;">
									<span style="font-size: 14px;vertical-align: middle;">组名&nbsp;</span>
									<input type="text"  name="userGroupName" value="${userGroupName }" class="inputS1"/>&nbsp;&nbsp;
									<input type="submit" value="查询" class="sbtn25 sbtn25_1" style="font-size: 16px;"/>

									<div style="padding: 5px;color: #666565;text-align: right;float: right;margin-right: 20px;">
									</div>
								</div>
								</form>
								
							</div>
							
							<div style="margin-top: 15px;">
							
							<div style="padding: 5px;color:#666565; ">
								
								<div style="">
									<table class="contacts-table" width="100%" cellpadding="0" cellspacing="0">
									<tr>
										<th style="text-align: center;" width="30"> <input type="checkbox" class="checkboxAll"></th>
										<th align="left">小组名</th>
									</tr>

										<c:choose>
											<c:when test="${fn:length(groupList) > 0}">

												<c:forEach items="${groupList }" var="en">
													<tr>
														<td align="center"><input type="checkbox" class="quItemCheckbox" name="groupId" value="${en.id }"></td>
														<td align="left">${en.userGroupName }</td>
													</tr>
												</c:forEach>

											</c:when>
											<c:otherwise>
												<tr>
													<td colspan="7">

														<div style="padding: 60px;font-size: 22px;text-align: center;color: #b1aeae;">还没有数据！</div>

													</td>
												</tr>
											</c:otherwise>
										</c:choose>

								</table>
								
								</div>
								
							</div>
							</div>
						<div class="contacts_search" style="padding: 5px;color:#666565;margin-top: 15px;" >
								<form id="" action="#" method="post">
								<div style="padding-left: 30px;padding-top: 8px;padding-bottom: 8px;">
								<input type="hidden" name="ctx" value=${ctx } id="ctx">
								<input type="hidden" name="surveyId" value=${surveyId } id="surveyId">
	 								<button type="button" class="btn btn-default" id="saveBtn">保存</button>
	
									<div style="padding: 5px;color: #666565;text-align: right;float: right;margin-right: 20px;">
									</div>
								</div>
								</form>
								
						</div>
						<div style="display:none">
						<c:forEach items="${surveyGroupList }" var="gn">
						<input type="checkbox"  name="groupIdChecked" value="${gn.groupId }">
						</c:forEach>
						</div>
					</div>
					
				</div>
			</div>
			
		</div>
		</div>
	</div>

	
	
<script type="text/javascript">
$(".disUser_a").click(function(){
	var thVal=$(this).text();
	var th=$(this);
	var thTitle = $(this).attr("title");
	if(confirm("确定要"+thTitle+"吗？")){
		var url=$(this).attr("href");
		var data="";
		$.ajax({
			url:url,
			data:data,
			type:'post',
			success:function(msg){
				if(msg=="true"){
//					$(th).parents("tr").remove();
					if(thVal=="删除"){
						$(th).parents("tr").remove();
					}else{
						window.location.reload(true);
					}
					/*if(thVal=="禁用"){
						$(th).text("启用");
						$(th).parents("tr").find("td:eq(4)").text("不可用");
					}else{
						$(th).text("禁用");
						$(th).parents("tr").find("td:eq(4)").text("可用");
					}*/
				}
			}
		});
	}
	//delete
	return false;
});

$("select[name='status']").val("${status}");

resizeBodyWidth();
$("a").attr("hidefocus",true);

</script>
</body>
</html>
